package com.zhang.web.services;

import java.util.List;

import org.hibernate.SessionFactory;

import com.zhang.pojo.Shop;
import com.zhang.pojo.Tables;
import com.zhang.pojo.User;

public class TablesDAO {
	private SessionFactory sessionFactory;

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	public List<Tables> allTables(){
		List<Tables> list = this.sessionFactory.openSession().createQuery("from Tables").list();
		if(list.size()>0)
			return list;
		else
			return null;
	}
	
	public List<Tables> tablesByShop(Shop shop){
		List<Tables> list = this.sessionFactory.openSession().createQuery("from Tables tables where tables.shop = ?").setParameter(0, shop).list();
		if(list.size()>0)
			return list;
		else
			return null;
	}
	
	public void updateTable(String state,int id){
		this.sessionFactory.openSession().createQuery("update from Tables itables set itables.state = ? where itables.id = ?")
				.setString(0, state).setLong(1, id).executeUpdate();

	}
	
	public void insertTable(Tables table) {		
		this.sessionFactory.openSession().save(table);
	}
}
